<template>
  <div class="wrapper">
    <div></div>
    <div v-on:mouseover="stop()" v-on:mouseout="move()" class="swiper">
      <transition-group tag="ul" name="image">
        <li v-for="(items, index) in list" v-show="index === num" :key="items">
          <img :src="items" alt="" />
        </li>
      </transition-group>
      <div class="circle">
        <span
          v-for="(items, index) in data"
          class="nav"
          @click="change(index)"
          :class="{ active: index == num }"
          :key="index"
        ></span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      data: ["1", "2", "3"],
      time: "",
      num: 0,
      list: [
        "https://img0.baidu.com/it/u=239636789,1069687354&fm=26&fmt=auto",
        "https://img1.baidu.com/it/u=3239688802,3629069115&fm=26&fmt=auto",
        "https://img0.baidu.com/it/u=947321454,3654758693&fm=26&fmt=auto",
      ],
    };
  },
  methods: {
    play() {
      this.time = setInterval(() => {
        this.num++;
        if (this.num == 3) {
          this.num = 0;
        }
      }, 5000);
    },
    change(i) {
      this.num = i;
    },
    stop() {
      clearInterval(this.time);
    },
    move() {
      this.play();
    },
  },
  created() {
    this.play();
  },
};
</script>

<style lang='less' scoped>
.wrapper {
  height: 360px;
  width: 100%;
}
.swiper {
  position: relative;
  
}
img {
  width: 100%;
  height: 360px;
}
li {
  width: 100%;
  height: 360px;
  border: 5px solid white;
  color: white;
  position: absolute;
}
ul {
  width: 100%;
  height: 360px;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}
.circle {
  margin-top: 30px;
  position: absolute;
  bottom: 30px;
  right: 50px;
  transform: translate(-50%, 0);
}
.nav {
  background-color: #fff;
  color: white;
  margin-right: 10px;
  font-size: 20px;
  display: inline-block;
  width: 33.4px;
  height: 4px;
  opacity: 0.5;
}
.active {
  opacity: 1;
}

.image-enter {
  transform: translateX(0);
}
.image-enter-active {
  transition: all 1.5s linear;
}
.image-enter-to {
  transform: translateX(0);
}

.image-leave {
  transform: translateX(0);
}
.image-leave-active {
  transition: all 1.5s linear;
}
.image-leave-to {
  transform: translateX(0);
}
</style>

